package online.misscl.lsy.controller.back;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import online.misscl.lsy.controller.BaseController;
import online.misscl.lsy.entity.ConsultationAnnouncement;
import online.misscl.lsy.entity.dto.vo.TableDataInfoVo;
import online.misscl.lsy.service.ConsultationAnnouncementService;
import online.misscl.lsy.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * project name: IntelliJ IDEA
 * Date: 2023/3/13 23:16
 *
 * @PackageName: online.misscl.lsy.controller.back
 * @ClassName: AnnoController
 * @Author: code mover
 * @Version:
 * @Description:
 */
@RestController
@RequestMapping("/back")
public class AnnoController extends BaseController {

    @Autowired
    private ConsultationAnnouncementService annService;

    @GetMapping("/annos/{pageSize}/{pageNum}")
    public TableDataInfoVo<List<ConsultationAnnouncement>> list(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        Page<ConsultationAnnouncement> page = annService.annoList(pageNum, pageSize);
        return getDataTable(page.getRecords(),page.getTotal());
    }

    @GetMapping("/anno/{annoId}")
    public AjaxResult getAnnoOne(@PathVariable Integer annoId){

        LambdaQueryWrapper<ConsultationAnnouncement> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ConsultationAnnouncement::getConsultationAnnouncementId,annoId);
        ConsultationAnnouncement one = annService.getOne(wrapper);
        return AjaxResult.success(one);
    }
    @PutMapping("/annos")
    public AjaxResult updateAnno(@RequestBody ConsultationAnnouncement consultationAnnouncement){
        return toAjax(annService.updateById(consultationAnnouncement));
    }
    @DeleteMapping("/anno/{annoId}")
    public AjaxResult deleteAnno(@PathVariable Integer annoId){
        ConsultationAnnouncement announcement = new ConsultationAnnouncement();
        announcement.setConsultationAnnouncementId(annoId);
        return toAjax(annService.removeById(announcement));
    }
    @PostMapping("/annos")
    public AjaxResult saveAnno(@RequestBody ConsultationAnnouncement consultationAnnouncement){
        return toAjax(annService.save(consultationAnnouncement));
    }

}
